<?php
include_once(DB_FILE);

function parserRasponi()
{
    global $DATA_SCHEDULE_SIMUL;

        $msql  = new Db;
        $msql->connect();

	$filename=RASPONI_DIR."H_Rasponi.txt";
        echo $filename;
	
	$log=new FileLog();
	$log->writeLog( __FUNCTION__."$filename");
	$log->close();
	
        $ins_query="INSERT INTO rasponi_tmp (data,valore) VALUES ";
        $query_zero="INSERT INTO rasponi (data,valore) VALUES ";
        $str_query="";

        $lines = file($filename); 
        $num_row=count($lines);
        echo $num_row;
        $data=strtotime( $DATA_SCHEDULE_SIMUL );

        for($i=0;$i<$num_row;$i++)
        { 
            $string = $lines[$i];
            $str_tmp=preg_replace(array('/\s\s+/','/ /'), ' ', $string);

            $arr_str=preg_split('/ /',$str_tmp,-1, PREG_SPLIT_NO_EMPTY);

            $str_query=$ins_query;

            $data_sec=$data + 3600*$arr_str[0];
            $data_less_hour=strftime('%Y-%m-%d %H:%M:%S',$data_sec);

            #echo "DATA $data\n";

            //if($arr_str[0]=='0.0') //data con 0 data di scedulazione
            if($i == 48)
            {
             $query_zero.="('".$data_less_hour."','".$arr_str[1]."');";
             $msql->execute($query_zero);
            }

           # print_r($arr_str);
            if(count($arr_str) == 2) 
            {
             $str_query.="('$data_less_hour','$arr_str[1]');";
            }
         //   echo $str_query."\n";
        //             if($i!=$num_row-1)
        //               $str_query.=",";
        //             else
        //                $str_query.=";";
        //$string_tmp=ltrim($arr_str);
            echo "$str_query = $arr_str[0]\n";
            $msql->execute($str_query);

        }
    //	$str_query=$ins_query.$str_query;
    //  $msql->execute($str_query);
         $msql->disconnettiDB();
	return 0;
}
?>